<template>
  <el-row class="tree-tools" style="width:100%">
    <el-col class="left" :span="18">
      <i class="el-icon-s-home"></i>
      <span>{{ item.name }}</span>
    </el-col>
    <el-col class="right" :span="6">
      <span>{{ item.manager }}</span>
      <el-dropdown @command="mycommand">
        <span class="el-dropdown-link">
          操作<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="add">添加子部门</el-dropdown-item>
          <el-dropdown-item command="edit" v-if="!item.isTop"
            >查看部门</el-dropdown-item
          >
          <el-dropdown-item command="del" v-if="!item.isTop"
            >删除部门</el-dropdown-item
          >
        </el-dropdown-menu>
      </el-dropdown>
    </el-col>
  </el-row>
</template>

<script>
import { delDeptApi } from '@/api/departments.js'
export default {
  props: ['item'],
  methods: {
    async mycommand (command) {
      if (command == 'add') {
        this.$emit('addShow',this.item.id)
      } else if (command == 'edit') {

      } else if (command == 'del') {
       try{
          await this.$confirm('是否删除当前部门', '警告')
        await delDeptApi(this.item.id)
        this.$emit('updatedata')
        this.$message.success('删除部门成功')
       } catch{
         console.log('取消删除 & 删除出错')
       }
      }
    }
  }
}
</script>

<style lang="scss">
.tree-tools {
  .left {
    font-weight: 700;
    i {
      margin-right: 8px;
    }
  }
  .right {
    text-align: right;
    span {
      margin-right: 20px;
    }
    .el-dropdown-link {
      font-size: 16px;
    }
  }
}
</style>
